package com.pug.web.order;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pug.annotation.EnableNoToken;
import com.pug.annotation.SaveOrderMessage;
import com.pug.bo.UserOrderBo;
import com.pug.pojo.UserOrder;
import com.pug.result.ex.KsdBusinessException;
import com.pug.service.message.MessageService;
import com.pug.service.order.IUserOrderService;
import com.pug.service.order.UserOrderServiceImpl;
import com.pug.vo.Order;
import com.pug.vo.UserOrderVo;
import com.pug.vo.UserVo;
import com.pug.web.BaseController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Author: lqm
 * create: 2022/3/29 14:49
 * Lover: lqx
 *
 * @see
 */
@RestController
public class MyOrderController extends BaseController {
    @Resource
    UserOrderServiceImpl userOrderService;
    @Resource
    MessageService messageService;

    /***
     * @param  userOrderVo
     * @return
     */
    @ApiOperation("用户订单查询")
    @PostMapping("/user/order/load")
    public Page<UserOrder> findUserOrders1(@RequestBody UserOrderVo userOrderVo) {
        return userOrderService.findUserOrders(userOrderVo);
    }
    /***
     * @return
     */
    @PostMapping("/user/status/load")
    @ApiOperation("用户订单状态查询")
    public List<Map<String, Object>> selectOrderStatusInfo() {
        return userOrderService.selectOrderStatusInfo();
    }

    //用户订购酒店
    @SaveOrderMessage
    @EnableNoToken(true)
    @PostMapping("/order/hotel")
    public void orderHotel(@RequestBody Order order){
        //收费
        System.out.println("收费");
        //订单信息存储
    }
    //正式用户订单处理
    @EnableNoToken(true)
    @PostMapping("/user/order/create")
    public UserOrderBo makeOrder(@RequestBody UserVo userVo){
      try{
          UserOrderBo userOrder = userOrderService.createUserOrder(userVo);
          if(userOrder==null){
              throw new KsdBusinessException(500,"下单失败");
          }
          return userOrder;
      }catch (Exception e){
          throw new KsdBusinessException(500,"下单出现异常");
      }
    }
}
